package io.handlerstream;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.junit.Test;

public class BufferedReaderWriterDemo {
	@Test
	public void read() {
		try {
			//1.
			FileReader fr = new FileReader("b.txt");
			BufferedReader br = new BufferedReader(fr);
			
			char[] arr = new char[100];
			br.read(arr);
			
			// 3.关闭
			br.close();
			fr.close();
			
			System.out.println(arr);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	@Test
	public void write() {
		try {
			FileWriter fw = new FileWriter("c.txt",true);
			BufferedWriter bw = new BufferedWriter(fw);
			
			bw.write("hahahahah");
			bw.flush();
			
			//关闭
			bw.close();
			fw.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
